package com.xiaoda.service.impl;

import com.xiaoda.dao.*;
import com.xiaoda.entity.User;
import com.xiaoda.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    ArticleDao articleDao;

    @Autowired
    CollectDao collectDao;

    @Autowired
    CommentDao commentDao;

    @Autowired
    LikeDao likeDao;

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public User findById(String account) {
        return userDao.findById(account);
    }

    @Override
    public User userLogin(String account, String password) {
        return userDao.userLogin(account, password);
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public List<User> recommendedAttention(String uid) {
        return userDao.recommendedAttention(uid);
    }

    @Override
    public int updateUser(User user) {
        return userDao.updateUser(user);
    }

    @Override
    public List<User> findAllByKeyword(Map<String, Object> map) {
        return userDao.findAllByKeyword(map);
    }

    @Transactional
    @Override
    public int deleteByAccount(String account) {
        collectDao.deleteByUid(account);
        commentDao.deleteByUid(account);
        likeDao.deleteByUid(account);
        articleDao.deleteByUid(account);
        return userDao.deleteByAccount(account);
    }

    @Override
    public int addFullUser(User user) {
        return userDao.addFullUser(user);
    }

}
